home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / protocols / advice.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2008-10-13  |  6KB  |  198 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. from __future__ import generators
  5. from new import instancemethod
  6. from types import ClassType, FunctionType, InstanceType
  7. import sys
  8. __all__ = [
  9.     'metamethod',
  10.     'supermeta',
  11.     'getMRO',
  12.     'classicMRO',
  13.     'mkRef',
  14.     'StrongRef',
  15.     'addClassAdvisor',
  16.     'isClassAdvisor',
  17.     'add_assignment_advisor',
  18.     'determineMetaclass',
  19.     'getFrameInfo',
  20.     'minimalBases']
  21. from peak.util import decorators
  22.  
  23. def addClassAdvisor(callback, depth = 2, frame = None):
  24.     warn = warn
  25.     import warnings
  26.     warn(addClassAdvisor.__doc__, DeprecationWarning, 2)
  27.     if not depth:
  28.         pass
  29.     return decorators.decorate_class(callback, 0 + 1, frame)
  30.  
  31.  
  32. def add_assignment_advisor(callback, depth = 2, frame = None):
  33.     warn = warn
  34.     import warnings
  35.     warn(add_assignment_advisor.__doc__, DeprecationWarning, 2)
  36.     if not depth:
  37.         pass
  38.     return decorators.decorate_assignment(callback, 0 + 1, frame)
  39.  
  40.  
  41. def getFrameInfo(frame):
  42.     warn = warn
  43.     import warnings
  44.     warn(getFrameInfo.__doc__, DeprecationWarning, 2)
  45.     return decorators.frameinfo(frame)
  46.  
  47.  
  48. def determineMetaclass(bases, explicit_mc = None):
  49.     warn = warn
  50.     import warnings
  51.     warn(determineMetaclass.__doc__, DeprecationWarning, 2)
  52.     return decorators.metaclass_for_bases(bases, explicit_mc)
  53.  
  54.  
  55. def isClassAdvisor(ob):
  56.     warn = warn
  57.     import warnings
  58.     warn(isClassAdvisor.__doc__, DeprecationWarning, 2)
  59.     return decorators.metaclass_is_decorator(ob)
  60.  
  61.  
  62. def metamethod(func):
  63.     return (property,)((lambda ob: func.__get__(ob, ob.__class__)))
  64.  
  65.  
  66. try:
  67.     from ExtensionClass import ExtensionClass
  68. except ImportError:
  69.     ClassicTypes = ClassType
  70.  
  71. ClassicTypes = (ClassType, ExtensionClass)
  72.  
  73. def classicMRO(ob, extendedClassic = False):
  74.     stack = []
  75.     push = stack.insert
  76.     pop = stack.pop
  77.     push(0, ob)
  78.     while stack:
  79.         cls = pop()
  80.         yield cls
  81.         p = len(stack)
  82.         for b in cls.__bases__:
  83.             push(p, b)
  84.         
  85.     if extendedClassic:
  86.         yield InstanceType
  87.         yield object
  88.     
  89.  
  90.  
  91. def getMRO(ob, extendedClassic = False):
  92.     if isinstance(ob, ClassicTypes):
  93.         return classicMRO(ob, extendedClassic)
  94.     elif isinstance(ob, type):
  95.         return ob.__mro__
  96.     
  97.     return (ob,)
  98.  
  99.  
  100. try:
  101.     from _speedups import metamethod, getMRO, classicMRO
  102. except ImportError:
  103.     pass
  104.  
  105.  
  106. def supermeta(typ, ob):
  107.     starttype = type(ob)
  108.     mro = starttype.__mro__
  109.     if typ not in mro:
  110.         starttype = ob
  111.         mro = starttype.__mro__
  112.     
  113.     mro = iter(mro)
  114.     for cls in mro:
  115.         if cls is typ:
  116.             mro = [ cls.__dict__ for cls in mro ]
  117.             break
  118.             continue
  119.         []
  120.     else:
  121.         raise TypeError('Not sub/supertypes:', starttype, typ)
  122.     typ = type(ob)
  123.     
  124.     class theSuper([], 'theSuper', (object,)):
  125.         
  126.         def __getattribute__(self, name):
  127.             for d in mro:
  128.                 if name in d:
  129.                     descr = d[name]
  130.                     
  131.                     try:
  132.                         descr = descr.__get__
  133.                     except AttributeError:
  134.                         return descr
  135.  
  136.                     return descr(ob, typ)
  137.                     continue
  138.             
  139.             return object.__getattribute__(self, name)
  140.  
  141.  
  142.     return theSuper()
  143.  
  144.  
  145. def minimalBases(classes):
  146.     warn = warn
  147.     import warnings
  148.     warn('protocols.advice.minimalBases is deprecated; please do not use it', DeprecationWarning, 2)
  149.     classes = _[1]
  150.     candidates = []
  151.     for m in classes:
  152.         for n in classes:
  153.             if issubclass(n, m) and m is not n:
  154.                 break
  155.                 continue
  156.             []
  157.         elif m in candidates:
  158.             candidates.remove(m)
  159.         
  160.         candidates.append(m)
  161.     
  162.     return candidates
  163.  
  164. from weakref import ref
  165.  
  166. class StrongRef(object):
  167.     __slots__ = 'referent'
  168.     
  169.     def __init__(self, referent):
  170.         self.referent = referent
  171.  
  172.     
  173.     def __call__(self):
  174.         return self.referent
  175.  
  176.     
  177.     def __hash__(self):
  178.         return hash(self.referent)
  179.  
  180.     
  181.     def __eq__(self, other):
  182.         return self.referent == other
  183.  
  184.     
  185.     def __repr__(self):
  186.         return 'StrongRef(%r)' % self.referent
  187.  
  188.  
  189.  
  190. def mkRef(ob, *args):
  191.     
  192.     try:
  193.         return ref(ob, *args)
  194.     except TypeError:
  195.         return StrongRef(ob)
  196.  
  197.  
  198.